package com.nuoniu.sibanyun.service.crm.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.crm.CrmCode;
import com.nuoniu.sibanyun.mapper.crm.CrmCodeMapper;
import com.nuoniu.sibanyun.service.crm.ICrmCodeService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 编码设置 服务实现类
 * </p>
 *
 * @author baiqiang
 * @since 2020-06-16
 */
@Service
public class CrmCodeServiceImpl extends ServiceImpl<CrmCodeMapper, CrmCode> implements ICrmCodeService {

    @Autowired
    private CrmCodeMapper crmCodeMapper;

    @Override
    public List<CrmCode> getCodeList() {
        UserInfo userInfo = UserThreadLocal.get();
        List<CrmCode> crmCodes = crmCodeMapper.getCodeList(userInfo.getCompanyId());
        if(crmCodes.size() == 0) {
            crmCodeMapper.saveAll(userInfo.getCompanyId(), userInfo.getCompanyName(), userInfo.getUserId(), userInfo.getRealName());
            crmCodes = crmCodeMapper.getCodeList(userInfo.getCompanyId());
        }
        return crmCodes;
    }
}
